#!/bin/bash
#set -n
#set -x
#:e! ~/src/vim-bash-hacks/src/bash/storegzip.sh
store_root="/cygdrive/j/store-2010-07-12"
if [[ ! -d $store_root ]] ; then
  mkdir -p $store_root
fi

export find_parms=
while (( $# > 0 )) ; do
	case $1 in
-xdev)
		export find_parms="$find_parms $1"
		shift 1
		;;
-*)
		export find_parms="$find_parms $1 '$2'"
		shift 2
		;;
*)
	break
	;;
  esac
done

function store_dir {
#set -x
export store_prefix=
while (( $# > 0 )) ; do
	case $1 in
-i)
	fadir="$2"
	echo "Ignoring $fadir."
	return
	;;
-prefix)
		export store_prefix="${2}_"
		shift 2
		;;
*)
	break
	;;
  esac
done

while (( $# > 0 )) ; do
adir="$1"
#Have find end file names with null (-print0).  Have cpio read file names
#ending in null (--null).
script -c "find '$adir' -print0 $find_parms | cpio -cov --null | gzip --verbose --fast -c | \
	 split --suffix-length=10 --bytes=1GB --numeric --verbose - '$store_root/store_cpio_data_${store_prefix}$adir'" "$store_root/store_cpio_data_${store_prefix}$adir.txt"
shift 1
done
}
store_dir -i "ACER"
store_dir -i "ATI"
store_dir -i "GTW"
store_dir -i "Netgear"
store_dir -i "PerfLogs"
store_dir -i "Program Files"
store_dir -i "Program Files (x86)"
store_dir -i "ProgramData"
store_dir -i "USR"
store_dir -i "Users"
store_dir -i "cygwin-1.7"
store_dir -i "home"
store_dir -i "mostdownloads"
store_dir -i "old cygwin"
store_dir -i "opt"
store_dir -i "var"
#Example of small directories.
#echo "undo!!!" && store_dir -prefix vimhack "vim-bash-hacks"
